<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>Document</title>
    <style>
    *{
        margin: 0;padding: 0;
    }
    #myCanvas{
        border: 1px solid red;
    }
    </style>
</head>
<body>
    <canvas id="myCanvas">
        
    </canvas>
    <script>
        var c = document.getElementById('myCanvas')
        var ctx = c.getContext("2d")
        ctx.fillstyle = 'red'
        ctx.fillRect(0,0,300,150)
        ctx.clearRect(10,10,150,50)
        var dis = 0
        function animation() {
            requestAnimationFrame(function(){
                ctx.clearRect(0,0,300,150)
                ctx.fillstyle = `rgb(${dis++},0,0)`
                ctx.fillText(dis++,110,90)
                ctx.font = "50px Verdana"
                animation()
                if (dis>=255) {
                    dis = 0
                }
            })
        }
        animation()
    </script>
</body>
</html>